package com.qf.servlet;

import com.qf.entity.Card2;
import com.qf.entity.PersonalCenter;
import com.qf.entity.User;
import com.qf.service.Card1Service;
import com.qf.service.Card2Service;
import com.qf.service.UserService;
import com.qf.service.impl.Card1ServiceImpl;
import com.qf.service.impl.Card2ServiceImpl;
import com.qf.service.impl.UserServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@WebServlet("/person")
public class PersonalCenterServlet extends BaseServlet{
    private UserService userService = new UserServiceImpl();
    private Card1Service card1Service = new Card1ServiceImpl();
    private Card2Service card2Service = new Card2ServiceImpl();
    private void personalCenter(HttpServletRequest req, HttpServletResponse resp) throws IOException, InvocationTargetException, IllegalAccessException {

        Integer id = (Integer) req.getSession().getAttribute("id");
        User user = userService.findOneById(id);
        List<Card2> card2List = card2Service.findByUid(id.toString());
        PersonalCenter personalCenter = new PersonalCenter(user.getUsername(),user.getPhone(),user.getId_num(),card2List);
        writeHTML(personalCenter,resp);
    }
}
